package cj.web.marriage.controllers;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import cj.utils.Constants;
import cj.utils.sms.SendSMSUtil;
import cj.web.admin.constants.MemuEnum;
import cj.web.marriage.domain.SetMeal;

@Path("/sendMsg")
public class SendMsgController {
	
	private static Logger logger = Logger.getLogger(SetMealController.class.getName());
	
	public final static String accountSid="8aaf0708559f32dd0155a061b0e70089";
	public final static String accountToken="ca8d98f8170b4293be592df629a8ea07";
	public final static String appId="8aaf070855ed9ef10155fd08aee90737";

	@Get("show")
	public String show(Model model,SetMeal setMeal) {
		//MemuEnum
        model.add("MemuEnum",MemuEnum.xqqfdx);
		return "/views/marriage/sendMsg.vm";
	}
	
	@Post("send")
	public String send(@Param("phone")String phone, @Param("tempid") String tempid) {
	
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		try {
			String returnFlag = SendSMSUtil.sendSMS(accountSid, accountToken, appId, phone, tempid, null);
			if(Constants.returnObj.returnFlag_flase.equals(returnFlag)){
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
			}
		} catch (Exception e) {
			// TODO: handle exception
			jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
		}
		
		return "@"+jo.toString();
	}
}